<<<<<<< HEAD
<<<<<<< HEAD
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Basic Layout - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
	<script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/jquery.serializejson.min.js"></script>

</head>
<body>

        <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'west',split:true" title="新闻分类" style="width:200px;">
                    <ul id="tt" class="easyui-tree">
                        <li>
                            <span>校园新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                            </ul>
                        </li>
                        <li>
                            <span>述评新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                             </ul>
                        </li>
                        <li>
                                <span>动态新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                </ul>
                            </li>
                            <li>
                                <span>综合新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                 </ul>
                            </li>
                    </ul>

                </div>
                <div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'">
                        <table id="dg"></table>
                        <div id="tb" style="padding:2px 5px;">
                            <input id="name" label="用户名称:" style="width:100%;">
                            <a href="#" id="searchData" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
                            <a href="#" id="addData" class="easyui-linkbutton" data-options="iconCls:'icon-add'">增加</a>
                            <a href="#" id="removesData" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
                        </div>

                        <div id="dlg" class="easyui-dialog" title="增加新闻" data-options="iconCls:'icon-save',closed: true" style="width:400px;height:300px;padding:10px">



                                <form id="ff" method="post" >
                                        <div style="margin-bottom:10px;">
                                            <label for="title">新闻标题:</label>
                                            <input name="title" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="autor">新闻作者:</label>
                                                <input name="autor" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="content">新闻内容:</label>
                                                <input name="content" type="text" style="width:300px;height:35px;">
                                        </div>
                                    </form>
                                        <div style="text-align:center;padding:5px 0">
                                            <a href="javascript:void(0)" class="easyui-linkbutton" id="submit" onclick="submitForm()" style="width:80px">提交</a>
                                            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">清空</a>
                                        </div>
                        </div>
                </div>
            </div>
</body>
</html>

<script>
 var newsId = '';
 $('#tt').tree({
        onClick:function(node){
            $('#dg').datagrid({
                queryParams: {
                    newsId: node._id
                }
            });
        }
});
//增加函数
 function submitForm(){
    $('#ff').form('submit',{
        onSubmit:function(){
           if($(this).form('enableValidation').form('validate')){
                // 将当前页面的表单信息进行获取，然后进行ajax请求
                var formData = $("#ff").serializeJSON();
                if(formData&& formData.title!=''&&formData.autor!=''&&formData.content!=''){
                    // update
                    $.ajax({
                        url:`http://10.31.162.63:3000/news`,
                        type:'post',
                        data: formData
                    }).done(function(res){
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                        $('#ff').form('clear');
                    })
                }else{
                    alert('请输入内容');
                }
           }
        }
    });
    return false; // 阻止默认事件
}
function clearForm(){
    $('#ff').form('clear');
}

//数据列表
$('#dg').datagrid({
    url:`${window.parent.globalURL}news/list`,
    fit:'true',
    border:false,
    pagination:true,
    toolbar:'#tb',
    columns:[[
        {field:'ck',checkbox:true},
        {field:'title',title:'新闻标题',width:350},
        {field:'autor',title:'新闻作者',width:100},
        {field:'content',title:'新闻内容',width:500},
        {field:'ctime',title:'发布时间',width:200},
        {field:'_id',title:'操作', width:80,
            formatter: function(value,row,index){
				return `<a href="javascript:void(0)" onclick="updateData('${row._id}')">修改</a> <a href="javascript:void(0)" onclick="deleteData('${row._id}')">删除</a>`
			}
		}
    ]]
});
//搜索
$("#searchData").click(function(){
    $('#dg').datagrid({
        queryParams: {
            name: $("#name").val()
        }
    });
})
//删除函数
function deleteData(id){
$.messager.confirm('确认对话框', '你确认删除?', function(r){
    if (r){
        $.ajax({
            url:`${window.parent.globalURL}news/${id}`,
            type:'delete'
        }).done(function(res){
            alert('删除成功')
            $("#dg").datagrid('reload');
        })
    }
});
}
//修改函数
function updateData(id){


        $.ajax({
            url:`http://localhost:3000/news/${id}`,
            type:'put'
        }).done(function(res){

            $('#dlg').dialog('open');
            $('#ff').form('load',res);
        })



}
function deleteDatas(){
    var rows = $('#dg').datagrid('getSelections');
    var ids = [];
    for(var i=0;i<rows.length;i++){
        ids.push(rows[i]._id);
    }
    $.messager.confirm('确认对话框', '你确认删除?', function(r){
            if (r){
                $.ajax({
                    url:`${window.parent.globalURL}/news/removes`,
                    type:'post',
                    data:{
                        ids: ids.toString()
                    }
                }).done(function(res){
                    $("#dg").datagrid('reload');
                })
            }
        });
}


//增加
$("#addData").click(function(){
    $('#dlg').dialog('open');
})
//删除多个
$("#removesData").click(function(){
    deleteDatas();
})
=======
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Basic Layout - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
	<script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/jquery.serializejson.min.js"></script>

</head>
<body>

        <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'west',split:true" title="新闻分类" style="width:200px;">
                    <ul id="tt" class="easyui-tree">
                        <li>
                            <span>校园新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                            </ul>
                        </li>
                        <li>
                            <span>述评新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                             </ul>
                        </li>
                        <li>
                                <span>动态新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                </ul>
                            </li>
                            <li>
                                <span>综合新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                 </ul>
                            </li>
                    </ul>

                </div>
                <div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'">
                        <table id="dg"></table>
                        <div id="tb" style="padding:2px 5px;">
                            <input id="name" label="用户名称:" style="width:100%;">
                            <a href="#" id="searchData" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
                            <a href="#" id="addData" class="easyui-linkbutton" data-options="iconCls:'icon-add'">增加</a>
                            <a href="#" id="removesData" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
                        </div>

                        <div id="dlg" class="easyui-dialog" title="增加新闻" data-options="iconCls:'icon-save',closed: true" style="width:400px;height:300px;padding:10px">



                                <form id="ff" method="post" >
                                        <div style="margin-bottom:10px;">
                                            <label for="title">新闻标题:</label>
                                            <input name="title" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="autor">新闻作者:</label>
                                                <input name="autor" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="content">新闻内容:</label>
                                                <input name="content" type="text" style="width:300px;height:35px;">
                                        </div>
                                    </form>
                                        <div style="text-align:center;padding:5px 0">
                                            <a href="javascript:void(0)" class="easyui-linkbutton" id="submit" onclick="submitForm()" style="width:80px">提交</a>
                                            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">清空</a>
                                        </div>
                        </div>
                </div>
            </div>
</body>
</html>

<script>
 var newsId = '';
 $('#tt').tree({
        onClick:function(node){
            $('#dg').datagrid({
                queryParams: {
                    newsId: node._id
                }
            });
        }
});
//增加函数
 function submitForm(){
    $('#ff').form('submit',{
        onSubmit:function(){
           if($(this).form('enableValidation').form('validate')){
                // 将当前页面的表单信息进行获取，然后进行ajax请求
                var formData = $("#ff").serializeJSON();
                if(formData&& formData.title!=''&&formData.autor!=''&&formData.content!=''){
                    // update
                    $.ajax({
                        url:`http://10.31.162.63:3000/news`,
                        type:'post',
                        data: formData
                    }).done(function(res){
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                        $('#ff').form('clear');
                    })
                }else{
                    alert('请输入内容');
                }
           }
        }
    });
    return false; // 阻止默认事件
}
function clearForm(){
    $('#ff').form('clear');
}

//数据列表
$('#dg').datagrid({
    url:`${window.parent.globalURL}news/list`,
    fit:'true',
    border:false,
    pagination:true,
    toolbar:'#tb',
    columns:[[
        {field:'ck',checkbox:true},
        {field:'title',title:'新闻标题',width:350},
        {field:'autor',title:'新闻作者',width:100},
        {field:'content',title:'新闻内容',width:500},
        {field:'ctime',title:'发布时间',width:200},
        {field:'_id',title:'操作', width:80,
            formatter: function(value,row,index){
				return `<a href="javascript:void(0)" onclick="updateData('${row._id}')">修改</a> <a href="javascript:void(0)" onclick="deleteData('${row._id}')">删除</a>`
			}
		}
    ]]
});
//搜索
$("#searchData").click(function(){
    $('#dg').datagrid({
        queryParams: {
            name: $("#name").val()
        }
    });
})
//删除函数
function deleteData(id){
$.messager.confirm('确认对话框', '你确认删除?', function(r){
    if (r){
        $.ajax({
            url:`${window.parent.globalURL}news/${id}`,
            type:'delete'
        }).done(function(res){
            alert('删除成功')
            $("#dg").datagrid('reload');
        })
    }
});
}
//修改函数
function updateData(id){


        $.ajax({
            url:`http://localhost:3000/news/${id}`,
            type:'put'
        }).done(function(res){

            $('#dlg').dialog('open');
            $('#ff').form('load',res);
        })



}
function deleteDatas(){
    var rows = $('#dg').datagrid('getSelections');
    var ids = [];
    for(var i=0;i<rows.length;i++){
        ids.push(rows[i]._id);
    }
    $.messager.confirm('确认对话框', '你确认删除?', function(r){
            if (r){
                $.ajax({
                    url:`${window.parent.globalURL}/news/removes`,
                    type:'post',
                    data:{
                        ids: ids.toString()
                    }
                }).done(function(res){
                    $("#dg").datagrid('reload');
                })
            }
        });
}


//增加
$("#addData").click(function(){
    $('#dlg').dialog('open');
})
//删除多个
$("#removesData").click(function(){
    deleteDatas();
})
>>>>>>> 293ad1b60d38214e296e0ea44938c28e0632ebc1
=======
<<<<<<< HEAD
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Basic Layout - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
	<script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/jquery.serializejson.min.js"></script>

</head>
<body>

        <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'west',split:true" title="新闻分类" style="width:200px;">
                    <ul id="tt" class="easyui-tree">
                        <li>
                            <span>校园新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                            </ul>
                        </li>
                        <li>
                            <span>述评新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                             </ul>
                        </li>
                        <li>
                                <span>动态新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                </ul>
                            </li>
                            <li>
                                <span>综合新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                 </ul>
                            </li>
                    </ul>

                </div>
                <div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'">
                        <table id="dg"></table>
                        <div id="tb" style="padding:2px 5px;">
                            <input id="name" label="用户名称:" style="width:100%;">

                            <a href="#" id="searchData" class="easyui-linkbutton" iconCls="icon-search">Search</a>
                            <a href="#" id="addData" class="easyui-linkbutton" data-options="iconCls:'icon-add'">Add</a>
                            <a href="#" id="removesData" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">Remove</a>
                        </div>

                        <div id="dlg" class="easyui-dialog" title="增加新闻" data-options="iconCls:'icon-save',closed: true" style="width:400px;height:300px;padding:10px">



                                <form id="ff" method="post" >
                                        <div style="margin-bottom:10px;">
                                            <label for="title">新闻标题:</label>
                                            <input name="title" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="autor">新闻作者:</label>
                                                <input name="autor" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="content">新闻内容:</label>
                                                <input name="content" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="releasetime">发布时间:</label>
                                                <input name="releasetime" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <center>
                                            <!-- <input type="submit" id="submit" style="width:80px;padding:10px 0;font-size:18px" value="提交" onclick="submitForm()"> -->
                                        </center>
                                    </form>
                                        <div style="text-align:center;padding:5px 0">
                                            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
                                            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">Clear</a>
                                        </div>
                        </div>
                </div>
            </div>
</body>
</html>

<script>


 var newsId = '';
 $('#tt').tree({
        url:`${window.parent.globalURL}cate/list/1`,
        onClick:function(node){
            $('#dg').datagrid({
                queryParams: {
                    newsId: node._id
                }
            });
        }
});

 function submitForm(){
    $('#ff').form('submit',{
        onSubmit:function(){
           if($(this).form('enableValidation').form('validate')){
                // 将当前页面的表单信息进行获取，然后进行ajax请求
                var formData = $("#ff").serializeJSON();
                console.log(formData._id.length);
                if(formData._id.length > 0){
                    // update
                    $.ajax({
                        url:`${window.parent.globalURL}news/${formData._id}`,
                        type:'put',
                        data: formData
                    }).done(function(res){
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                        $('#ff').form('clear');
                    })
                }else{
                    // add
                    delete formData._id;
                    $.ajax({
                        url:`${window.parent.globalURL}news`,
                        type:'post',
                        data: formData
                    }).done(function(res){
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                        $('#ff').form('clear');
                    })

                }


           }
            // 表单验证
        }

    });
    return false; // 阻止默认事件
}
function clearForm(){
    $('#ff').form('clear');
}

$('#dg').datagrid({
    url:'http://localhost:3000/news/list',
    fit:'true',
    border:false,
    pagination:true,
    toolbar:'#tb',
    columns:[[
        {field:'ck',checkbox:true},
        {field:'title',title:'新闻标题',width:450},
        {field:'autor',title:'新闻作者',width:100},
        {field:'content',title:'新闻内容',width:500},
        {field:'releasetime',title:'发布时间',width:100},
        {field:'_id',title:'操作', width:80,
            formatter: function(value,row,index){
				return `<a href="javascript:void(0)" onclick="updateData('${row._id}')">修改</a> <a href="javascript:void(0)" onclick="deleteData('${row._id}')">删除</a>`
			}
		}
    ]]
});

function deleteData(id){

    $.messager.confirm('确认对话框', '你确认删除?', function(r){
        if (r){

            $.ajax({
                url:`${window.parent.globalURL}news/${id}`,
                type:'delete'
            }).done(function(res){
                $("#dg").datagrid('reload');
            })
        }
    });

}

function updateData(id){

    $.ajax({
        url:`${window.parent.globalURL}news/${id}`,
        type:'post'
    }).done(function(res){
        $('#ff').form('load',res);
        $('#dlg').dialog('open');
    })

}

function deleteDatas(){
  var rows = $('#dg').datagrid('getSelections');
  var ids = [];
  for(var i=0;i<rows.length;i++){
    ids.push(rows[i]._id);
  }

  $.messager.confirm('确认对话框', '你确认删除?', function(r){
        if (r){
            $.ajax({
                url:`${window.parent.globalURL}news/removes`,
                type:'post',
                data:{
                    ids: ids.toString()
                }
            }).done(function(res){
                $("#dg").datagrid('reload');
            })
        }
    });
}

$("#searchData").click(function(){
    $('#dg').datagrid({
        queryParams: {
            title: $("#title").val()
        }
    });
})


$("#addData").click(function(){
    $('#dlg').dialog('open');
})

$("#removesData").click(function(){
    deleteDatas();
})
=======
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Basic Layout - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
	<script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/jquery.serializejson.min.js"></script>

</head>
<body>

        <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'west',split:true" title="新闻分类" style="width:200px;">
                    <ul id="tt" class="easyui-tree">
                        <li>
                            <span>校园新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                            </ul>
                        </li>
                        <li>
                            <span>述评新闻</span>
                            <ul>
                                <li> <span>校园快讯</span></li>
                                <li><span>通知公告</span></li>
                                <li><span>学生活动</span></li>
                             </ul>
                        </li>
                        <li>
                                <span>动态新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                </ul>
                            </li>
                            <li>
                                <span>综合新闻</span>
                                <ul>
                                    <li> <span>校园快讯</span></li>
                                    <li><span>通知公告</span></li>
                                    <li><span>学生活动</span></li>
                                 </ul>
                            </li>
                    </ul>

                </div>
                <div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'">
                        <table id="dg"></table>
                        <div id="tb" style="padding:2px 5px;">
                            <input id="name" label="用户名称:" style="width:100%;">

                            <a href="#" id="searchData" class="easyui-linkbutton" iconCls="icon-search">Search</a>
                            <a href="#" id="addData" class="easyui-linkbutton" data-options="iconCls:'icon-add'">Add</a>
                            <a href="#" id="removesData" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">Remove</a>
                        </div>

                        <div id="dlg" class="easyui-dialog" title="增加新闻" data-options="iconCls:'icon-save',closed: true" style="width:400px;height:300px;padding:10px">



                                <form id="ff" method="post" >
                                        <div style="margin-bottom:10px;">
                                            <label for="title">新闻标题:</label>
                                            <input name="title" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="autor">新闻作者:</label>
                                                <input name="autor" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="content">新闻内容:</label>
                                                <input name="autor" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <div style="margin-bottom:10px;">
                                                <label for="releasetime">发布时间:</label>
                                                <input name="releasetime" type="text" style="width:300px;height:35px;">
                                        </div>
                                        <center>
                                            <!-- <input type="submit" id="submit" style="width:80px;padding:10px 0;font-size:18px" value="提交" onclick="submitForm()"> -->
                                        </center>
                                    </form>
                                        <div style="text-align:center;padding:5px 0">
                                            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
                                            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">Clear</a>
                                        </div>
                        </div>
                </div>
            </div>
</body>
</html>

<script>
 var newsId = '';
 $('#tt').tree({
        url:`http://10.31.162.63:3000/cate/list/1`,
        onClick:function(node){
            $('#dg').datagrid({
                queryParams: {
                    newsId: node._id
                }
            });
        }
});

 function submitForm(){
    $('#ff').form('submit',{
        onSubmit:function(){
           if($(this).form('enableValidation').form('validate')){
                // 将当前页面的表单信息进行获取，然后进行ajax请求
                console.log('1111')
                var formData = $("#ff").serializeJSON();
                console.log(formData._id.length);
                if(formData._id.length > 0){
                    // update
                    $.ajax({
                        url:`http://10.31.162.63:3000/news/${formData._id}`,
                        type:'put',
                        data: formData
                    }).done(function(res){
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                        $('#ff').form('clear');
                    })
                }else{
                    // add
                    delete formData._id;
                    $.ajax({
                        url:`http://10.31.162.63:3000/news`,
                        type:'post',
                        data: formData
                    }).done(function(res){
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                        $('#ff').form('clear');
                    })

                }


           }
            // 表单验证
        }

    });
    return false; // 阻止默认事件
}
function clearForm(){
    $('#ff').form('clear');
}


$('#dg').datagrid({
    url:`http://10.31.162.63:3000/news/list`,
    fit:'true',
    border:false,
    pagination:true,
    toolbar:'#tb',
    columns:[[
        {field:'ck',checkbox:true},
        {field:'title',title:'新闻标题',width:100},
        {field:'autor',title:'新闻作者',width:100},
        {field:'content',title:'新闻内容',width:100},
        {field:'releasetime',title:'发布时间',width:100},
        {field:'_id',title:'操作', width:80,
            formatter: function(value,row,index){
				return `<a href="javascript:void(0)" onclick="updateData('${row._id}')">修改</a> <a href="javascript:void(0)" onclick="deleteData('${row._id}')">删除</a>`
			}
		}
    ]]
});

function deleteData(id){

    $.messager.confirm('确认对话框', '你确认删除?', function(r){
        if (r){

            $.ajax({
                url:`http://10.31.162.63:3000/news/${id}`,
                type:'delete'
            }).done(function(res){
                $("#dg").datagrid('reload');
            })
        }
    });

}

function updateData(id){

    $.ajax({
        url:`http://10.31.162.63:3000/news/${id}`,
        type:'get'
    }).done(function(res){
        $('#ff').form('load',res);
        $('#dlg').dialog('open');
    })

}

function deleteDatas(){
  var rows = $('#dg').datagrid('getSelections');
  var ids = [];
  for(var i=0;i<rows.length;i++){
    ids.push(rows[i]._id);
  }

  $.messager.confirm('确认对话框', '你确认删除?', function(r){
        if (r){
            $.ajax({
                url:`http://10.31.162.63:3000/news/removes`,
                type:'post',
                data:{
                    ids: ids.toString()
                }
            }).done(function(res){
                $("#dg").datagrid('reload');
            })
        }
    });


}

$("#searchData").click(function(){
    $('#dg').datagrid({
        queryParams: {
            name: $("#name").val()
        }
    });
})


$("#addData").click(function(){
    $('#dlg').dialog('open');
})

$("#removesData").click(function(){
    deleteDatas();
})
>>>>>>> 71cf024cfdc70f550f764ebaff25339cafefbf0f
>>>>>>> 3149a29e1f592792f6fc605dcbab84b249ce65e1
</script>